#ifndef PROXY_CONN_TCP_CONN_H_
#define PROXY_CONN_TCP_CONN_H_

#include "proxy/base/proxybase.h"

namespace proxy{

  class TcpConn : public boost::noncopyable,
    public boost::enable_shared_from_this < TcpConn > {
  public:
    typedef boost::shared_ptr<TcpConn> Ptr;
    typedef boost::function < void(socket_ptr connect,
      const boost::system::error_code& err) > CallbackConnect;

    // -------------------------------------------------------------------------
    // Call once at there, this interface can't ganerator a TcpClient object
    TcpConn(boost::asio::io_service& io_service, CallbackConnect call_back);
    virtual ~TcpConn();
    bool Start(const std::string domain, std::string port);
  private:
    void HandleResolve(const boost::system::error_code& err,
      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
    void ConnectServer(
      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
    void HandleConnect(const boost::system::error_code& err,
      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);

  private:
    boost::asio::io_service& io_service_;
    CallbackConnect SignalConnectResult;
    boost::asio::ip::tcp::resolver resolver_socket_;
    boost::asio::ip::tcp::resolver::iterator end_;
    socket_ptr connect_;
  };
}

#endif // PROXY_CONN_TCP_CONN_H_